package dkbta.processing.tasks;

import dkbta.ontology.elements.ElementDef;
import dkbta.processing.Patient;
import dkbta.processing.WorkQueue;

/**
 * A dummy task that is used for wrapping the actual receiving of remote element and
 * making the action a "primary" action so that the work queue will wait for it. All of
 * it's work consists of checking whether the remote element has been received and if not
 * to create an actual receiving task for it. <br>
 * <br>
 * In other words a <tt>PrimaryRemoteTask</tt> is an <tt>Observer</tt> over a
 * <tt>RemoteTask</tt> which is the <tt>Observable</tt><br>
 * <br>
 * Note that this kind of task is for a single patient and is always primary, thats the
 * whole of point of its existence.
 * 
 * @author Uri Kanonov
 */
public class PrimaryRemoteTask extends LocalTask{

	/**
	 * Initializes a primary remote computation task.
	 * 
	 * @param element The associated element
	 * @param patient The patient associated with the task
	 */
	public PrimaryRemoteTask(ElementDef element, Patient patient){
		super(element, true, patient);
	}

	/**
	 * Checks if the associated remote element has been computed, if it has been it merely
	 * returns true. Otherwise it creates a task to receive the element
	 * 
	 * @param wq A reference to the work queue
	 * @return Whether the remote element has been received
	 */
	@Override
	public boolean performTask(WorkQueue wq){
		return _patient.hasBeenComputed(element, wq, this);
	}	

	@Override
	public String toString(){
		return "Remote: PID = " + _patientId + ", " + element + " "
				+ ((isPrimary) ? "[PRIMARY]" : "");
	}
}
